package com.frogs.ucenter.v1.request;

import javax.servlet.http.HttpServletRequest;

import com.frogs.framework.util.StringUtil;
import com.frogs.framework.web.HttpRequestInfo;
import com.frogs.system.util.ApiUrlParamEnum;
import com.frogs.system.util.OpenPlatformEnum;
import com.frogs.system.web.api.request.Request;
import com.frogs.system.web.exception.RequestIllegalException;

public class UserBindEmailRequest extends Request{

	private static final long serialVersionUID = -4855893653103123434L;

	private int userId;
	
	private String email;
	
	private String ip;
	
	private int openPlatformId;
	
	public UserBindEmailRequest() {
		
	}
	
	@Override
	public void parse(HttpServletRequest request) {
		
		HttpRequestInfo requestInfo = new HttpRequestInfo(request);
		
		this.userId = requestInfo.getIntParameter(ApiUrlParamEnum.userId.getParamName(), 0);
		this.email = requestInfo.getParameter(ApiUrlParamEnum.email.getParamName(), "");
		this.ip = requestInfo.getParameter(ApiUrlParamEnum.ip.getParamName(), requestInfo.getUserIp());
		this.openPlatformId = requestInfo.getIntParameter(ApiUrlParamEnum.openPlatformId.getParamName(), OpenPlatformEnum.WECHAT_HDC.getId());
		if (userId < 0) {
			throw new RequestIllegalException("error userId: " + userId);
		}
		if (!StringUtil.isEmail(email)) {
			throw new RequestIllegalException("邮箱格式有误");
		}
	}

	public int getUserId() {
		return userId;
	}

	public void setUserId(int userId) {
		this.userId = userId;
	}

	public String getEmail() {
		return email;
	}

	public void setEmail(String email) {
		this.email = email;
	}
	
	public String getIp() {
		return this.ip;
	}
	
	public void setIp(String ip) {
		this.ip = ip;
	}

	public int getOpenPlatformId() {
		return openPlatformId;
	}

	public void setOpenPlatformId(int openPlatformId) {
		this.openPlatformId = openPlatformId;
	}
	
}
